<?php
if (isset($InputData["list_type"])) {
    $InputData['list_type'] = (int)$InputData['list_type'];
    require_once("{$CfgPara->root}/model/user.m.php");
    $myUser = new user_m($CfgPara->database);
    $user_list_id = 0;
    $userCount = 0;
    if ($InputData["list_type"] == user_m::ListSearch) {
        $userCount = -1; //搜索内容的数量在查询时确定 -1表示数量待定
    } elseif ($InputData["list_type"] == user_m::ListMyCollect) {
        if (!isset ($InputData['page_change'])) {
            $searchTittle = '收藏夹中的个人主页';
            require("{$viewRoot}search_bar{$viewEx}");
        }
        $userCount = -1;
    } elseif ($InputData["list_type"] == user_m::ListManage) {
        if (!isset($_SESSION['user_level']) || $_SESSION['user_level'] < 90 ||
            !isset($_SESSION['user_admin']) || $_SESSION['user_admin'] != 1
        ) {
            echo '无管理员权限进行用户管理';
            goto page_end;
        }
        if (isset($InputData['search_text'])) //管理用户下的搜索列表
        {
            $userCount = -1;
        } else {
            //20170207 优化 如果为换页 不再获取数量
            if (!isset($InputData['page_change'])) {
                $userCount = $myUser->user_count();
                $userTodayCount = $myUser->user_today_count();
            }
        }
        if (!is_numeric($userCount)) {
            echo $userCount;
            goto page_end;
        }
    } else {
        echo '查询的用户列表类型错误';
        goto page_end;
    }
    if ($userCount > 0 || $userCount == -1 || $userCount == -2) {
        if (isset($InputData['page_change']) && $InputData['page_change'] > 0) {
            $page_index = $InputData['page_change'];
        } else {
            $page_index = 1;
        }
        if (isset($InputData['search_text'])
            && isset($InputData['search_content'])
            && $InputData['search_content'] == 'user_list'
        ) {
            //如果有搜索内容 则增加搜索文本 且得出总数量
            $change_page_func = "get_search([x])";
            if ($page_index != 1 &&
                isset($InputData['search_result_count']) &&
                is_numeric($InputData['search_result_count']) &&
                $InputData['search_result_count'] >= 0
            ) {
                //如果页面已经记录过搜索结果总数量
                $userList = $myUser->user_list(
                    $InputData["list_type"],
                    $user_list_id,
                    $page_index,
                    $CfgPara->pagesize,
                    $InputData['search_text']);
                $userCount = $InputData['search_result_count'];
            } else {
                //如果页面为第一页 或没记录过总数量
                $userList = $myUser->user_list(
                    $InputData["list_type"],
                    $user_list_id,
                    $page_index,
                    $CfgPara->pagesize,
                    $InputData['search_text'], TRUE);
                $userCount = $myUser->user_list_count;
            }
            //返回的结果用连续两个||符号分隔 结果数量与内容
            echo $userCount . '||';
        } else {
            $change_page_func = "user_page_change({$InputData['list_type']},[x])";
            if ($userCount === -1) // 查询内容时同时 获取总量
            {
                $userList = $myUser->user_list(
                    $InputData["list_type"],
                    $user_list_id,
                    $page_index,
                    $CfgPara->pagesize,
                    NULL, TRUE);
                $userCount = $myUser->user_list_count;
            } else
                $userList = $myUser->user_list(
                    $InputData["list_type"],
                    $user_list_id,
                    $page_index,
                    $CfgPara->pagesize);
        }
        if (is_string($userList)) {
            echo($userList);
            goto page_end;
        }
        if (isset($change_page_func) && $CfgPara->pagesize > 0) {
            //连接分页类 在列表最后加入分页栏
            require_once("{$CfgPara->root}/class/paginate.class.php");
            $myPaginate = new paginate_c();
            $myPaginate->change_func = $change_page_func;
            $paginateMsg = $myPaginate->paginate($page_index, ceil($userCount / $CfgPara->pagesize));
        }
        if (!isset($InputData['page_change']))
            require("{$viewRoot}user_list{$viewEx}");//如果为初始加载则连接整个视图
        else
            require("{$viewRoot}user_list_page{$viewEx}");//如果为页面切换 则仅连接页面
    }
}

page_end:;